<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE8" />
<title></title>
<%@ include file="/WEB-INF/jsp/common/inc.jsp" %>
<script  type="text/javascript">
	var menuList;
	$(function (){
			//初始化所有项目被测件列表
			menuList = $("#menuList").bootstrapTable({
				url : '${_baseUrl}/codeCompare/selectTestSoftwareIncoming?rand='+Math.random(),
				pagination: true,
				pageList: [5, 10, 20, 50],
				data:{},
				queryParams: queryParams,
				clickToSelect : false,
		        columns: [{
		        	 field: 'checked',
		             checkbox: true,
		             width: 35,
		             height: 50,
		             align: 'center',
		             formatter: function(value, row, index){
		             	if(row.fileName == null || row.fileName == ""){
		             		return {
		             			disabled:true
		             		}
		             	}
		            	var index = row.fileName.substring(row.fileName.lastIndexOf(".")+1, row.fileName.length);
		            	if( index != "zip" && index != "rar" ){
		            		return {
		             			disabled:true
		             		}
		            	}
		             }
		         },{
		             field: 'projectId',
		             title: 'projectId',
		             visible:false,
		             width: 5,
		             align: 'center'
			     },{
		        	 field : 'projectName',
		         	 title : '项目名称',
		         	 width: 150,
		             height: 50,
		             align: 'center',
		             
		         },{
		        	 field : 'listName',
		         	 title : '配置项名称',
		             width: 150,
		             height: 50,
		             align: 'center',
		             
		         },{
		        	 field : 'fileName',
		         	 title : '文件名称',
		             width: 150,
		             height: 50,
		             align: 'center',
		             
		         },{
		        	 field : 'version',
		         	 title : '版本',
		             width: 120,
		             height: 50,
		             align: 'center'
		         }],
		        onLoadSuccess : function(data) {
		        	var cellIndex=parseInt($(".table_inline th").length);
		            $(".table_inline tr td").each(function(){
		                if(this.cellIndex != cellIndex){
		                    $(this).attr("title",$(this).text());
		                }
		            });
		  		}
		    });
		

		function queryParams(params){
			return {
				pageSize: params.limit,
				pageNo: params.pn,
			   sort : params.sort,
			   order : params.order,
			   projectIds:'${projectIds}',
			   listName:$("#listName").val(),
			   projectName:$("#listName").val()
			}
		}
	})
	
	/* 关闭弹出框 */
	function closeWin(){
		layer.closeAll();
	}
	
	function refreshTable(){
		menuList.bootstrapTable('refresh');
	}

	document.onkeydown=function(event) 
	{ 
		e = event ? event :(window.event ? window.event : null); 
		if(e.keyCode==13){ 
			refreshTable(); 
		} 
	} 
	function compare(){
		var row=$("#menuList").bootstrapTable('getSelections');
		if(row == null || row.length < 2){
			layer.msg("请选择两个不同版本软件源码压缩包比对");
			return;
		}
		if( row.length > 2){
			layer.msg("只能选择两个不同版本软件源码压缩包比对");
			return;
		}
		if( row[0].fileName == null || row[1].fileName ==null){
			layer.msg("选择配置项类型错误，请选择两个不同版本软件源码压缩包比对");
			return;
		}
		var index1 = row[0].fileName.substring(row[0].fileName.lastIndexOf(".")+1, row[0].fileName.length);
		var index2 = row[1].fileName.substring(row[1].fileName.lastIndexOf(".")+1, row[1].fileName.length);
		if(("rar" != index1 && "zip" != index1) || ("rar" != index2 && "zip" != index2)){
			layer.msg("选择配置项类型错误，请选择两个不同版本软件源码压缩包比对");
			return;
		}
		var ids = row[0].id + "," + row[1].id;
		layer.load(2);
		$.ajax({
            //请求方式
            type : "POST",
            //请求地址
            url : "${pageContext.request.contextPath}/codeCompare/compareIncoming",
            //数据，json字符串
            data : {"configIds":ids},
            //请求成功
            success : function(result) {
               layer.closeAll('loading');
               layer.msg(result.message);
            },
            //请求失败，包含具体的错误信息
            error : function(e){
            	layer.closeAll('loading');
                console.log(e.status);
                console.log(e.responseText);
            }
        });
	}
	
	function reportDown(){
		
		 var path = "${_baseUrl}/codeCompare/showReportWord?rand="+Math.random();
		   layerIndex = layer.open({
				 type: 2,
				 title:'项目配置项',
				 area: ['700px', '350px'],
				 shade: 0.3,
				 maxmin: true,
				 anim: -1,
				 content: path,
				 success: function(){
					
				 },
				 moveEnd: function(layero){
					 
				 },cancel: function(){ 
					 layer.closeAll();
				}
			});
		   layer.full(layerIndex);
	}
</script>
<style type="text/css">
.bootstrap-table{
width:100%;
}
.span_zhu{color:#ff0000bf; font-size: 13px;}
.search_container{margin-left:1%;}
</style>
</head>
<body>
<div class="submenu">
    <div class="func_header">
        <span title="被测件管理" >当前位置：被测件管理</span>
    </div>
     
    <div class="submenu_b">
    <div class="search_container" style="margin:0"><!--普通搜索-->
		<div class="func_search">
			<div class="func_search_div"></div>
			<input id="listName" type="text"  value="${listName }" placeholder="请输关键词..." />
			<a class="search_btn" href="javascript:;" onclick="refreshTable()"></a>
			
		</div>
	</div>
        <div class="btn_container"> 
           <a class="blue_btn" id="compare" href="javascript:;" onClick="compare();">比对</a>
           <a class="blue_btn" id="compare" href="javascript:;" onClick="reportDown();">报告下载</a>          
        </div>
    </div>
    <div style="overflow: auto; width:98%;margin: auto;">
    <span class="span_zhu">注：比对支持源代码压缩包类型：zip、rar<!-- ，其中rar只支持到winrar4.0版本以下 --></span>
    </div>
    
    <div style="overflow: auto; width:98%;margin: auto;">
	<table class="table table-bordered table_inline" id="menuList">
    </table>
    </div>
   
 </div>
</body>
</html>
